using Microsoft.AspNetCore.Mvc;
using ZR.Admin.WebApi.Filters;
using ZR.Model.Dto.Business.ProductionControl;
using ZR.Model.Models.ProductionControl;
using ZR.Service.IService.ProductionControl;

//创建时间：2024-10-08
namespace ZR.Admin.WebApi.Controllers
{
    /// <summary>
    /// 服务器配置表
    /// </summary>
    [Verify]
    [Route("run/serverconfig")]
    [ApiExplorerSettings(GroupName = "business")]
    public class ServerConfigController : BaseController
    {
        /// <summary>
        /// 服务器配置表接口
        /// </summary>
        private readonly IServerConfigService _ServerConfigService;

        public ServerConfigController(IServerConfigService ServerConfigService)
        {
            _ServerConfigService = ServerConfigService;
        }

        /// <summary>
        /// 查询服务器配置表列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "run:serverconfig:list")]
        public IActionResult QueryServerConfig([FromQuery] ServerConfigQueryDto parm)
        {
            var response = _ServerConfigService.GetList(parm);
            return SUCCESS(response);
        }

        /// <summary>
        /// 查询服务器配置表详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("{Id}")]
        [ActionPermissionFilter(Permission = "run:serverconfig:query")]
        public IActionResult GetServerConfig(int Id)
        {
            var response = _ServerConfigService.GetInfo(Id);

            var info = response.Adapt<ServerConfigDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加服务器配置表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "run:serverconfig:add")]
        [Log(Title = "服务器配置表", BusinessType = BusinessType.INSERT)]
        public IActionResult AddServerConfig([FromBody] ServerConfigDto parm)
        {
            var modal = parm.Adapt<ServerConfig>().ToCreate(HttpContext);

            var response = _ServerConfigService.AddServerConfig(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新服务器配置表
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "run:serverconfig:edit")]
        [Log(Title = "服务器配置表", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateServerConfig([FromBody] ServerConfigDto parm)
        {
            var modal = parm.Adapt<ServerConfig>().ToUpdate(HttpContext);
            var response = _ServerConfigService.UpdateServerConfig(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除服务器配置表
        /// </summary>
        /// <returns></returns>
        [HttpDelete("delete/{ids}")]
        [ActionPermissionFilter(Permission = "run:serverconfig:delete")]
        [Log(Title = "服务器配置表", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteServerConfig([FromRoute] string ids)
        {
            var idArr = Tools.SplitAndConvert<int>(ids);

            return ToResponse(_ServerConfigService.Delete(idArr));
        }
    }
}